package is.ru.honn.rupin.Test;

import is.ru.honn.rupin.data.BoardDataGateway;
import is.ru.honn.rupin.data.PinDataGateway;
import is.ru.honn.rupin.data.UserDataGateway;
import is.ru.honn.rupin.domain.Board;
import is.ru.honn.rupin.domain.Gender;
import is.ru.honn.rupin.domain.Pin;
import is.ru.honn.rupin.domain.User;
import is.ru.honn.rupin.service.BoardNotFoundException;
import is.ru.honn.rupin.service.UserNotFoundException;
import is.ruframework.data.RuDataAccessFactory;
import is.ruframework.domain.RuException;

import java.util.logging.Logger;

/**
 * Created by Sigrún Inga Kristinsdóttir.
 * Date: 18.10.2012
 * Time: 15:32
 * copyright (c) sigruninga&susanne
 *
 * @author Sigrún Inga kristindóttir og Susanne Götz
 * @version 1.1
 */

/**
 *  þessi test klasi er eingöngu fyrir okkur til að athuga ef við erum að skrá og fá gögnin í/ úr grunninn
 */
public class Test1 {
    public static void main(String[] args) throws UserNotFoundException, BoardNotFoundException {
        Logger log = Logger.getLogger("Test");
        RuDataAccessFactory factory = null;
        try
        {
            factory = RuDataAccessFactory.getInstance("data.xml");
        }
        catch (RuException e)
        {
            log.severe("Unable to load data specification in data.xml" + e.getMessage());
        }
        assert factory != null;
        UserDataGateway userDataGateway = (UserDataGateway)factory.getDataAccess("userDataAccess");
        userDataGateway.add(new User("Rip","Richard","Duck","rip@ru.is", "pir", Gender.MALE ));
        userDataGateway.add(new User("Rap","Ralf","Duck","rap@ru.is", "par", Gender.MALE ));
        userDataGateway.add(new User("Rup","Rufus","Duck","rup@ru.is", "pur", Gender.MALE ));

        System.out.println(userDataGateway.getUserByUsername("Rup"));

        BoardDataGateway boardDataGateway = (BoardDataGateway)factory.getDataAccess("boardDataAccess");
        boardDataGateway.add(new Board("RipNews", "News"));
        boardDataGateway.add(new Board("RapNews", "News"));
        boardDataGateway.add(new Board("RupNews", "News"));

        System.out.println(boardDataGateway.getBoardByKey("RipNews", "Rip"));

        PinDataGateway pinDataGateway = (PinDataGateway) factory.getDataAccess("pinDataAccess");
        pinDataGateway.add(new Pin("ripLink", "jejeje", "RipMynd"));
        pinDataGateway.add(new Pin("rapLink", "yha", "RupMynd"));
        pinDataGateway.add(new Pin("rupLink", "coooooooooooooool", "RupMynd"));

        pinDataGateway.getPinsByBoard(("RipNews"));

    }
}
